// 引入mock.js
const Mock = require('mockjs')

// 获取mock.Random对象
const Random = Mock.Random;
let Result = {
    code: 200,
    msg: "操作成功",
    data: null
}

/**
 * url: 表示要拦截的URL
 * post/get: 需要拦截的Ajax请求类型
 */
Mock.mock('/captcha', 'get', () => {
    Result.data = {
        // 获取一个32位的随机字符串
        token: Random.string(32),
        captchaImg: Random.dataImage("120x40", "11111")
    }
    return Result
})

/**
 * url: 表示要拦截的URL
 * post/get: 需要拦截的Ajax请求类型
 */
Mock.mock('/login', 'post', () => {
    // 无法在header中传入jwt
    // Result.code = 400
    // Result.msg = "验证码错误"
    return Result
})


Mock.mock('/sys/userInfo', 'get', () => {
    Result.data = {
        userInfo: {
            id: "1",
            username: "Test",
            avatar: "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg"
        }
    }
    return Result
})

Mock.mock('/logout', 'post', () => {
    return Result
})


Mock.mock('/sys/menu/nav', 'get', () => {
    let nav = [
        {
            name: 'SysManga',
            title: '系统管理',
            icon: 'el-icon-s-operation',
            path: '',
            component: '',
            children: [
                {
                    name: 'SysUser',
                    title: '用户管理',
                    icon: 'el-icon-s-custom',
                    path: '/sys/users',
                    children: []
                },
                {
                    name: 'SysRole',
                    title: '角色管理',
                    icon: 'el-icon-rank',
                    path: '/sys/roles',
                    children: []
                },
                {
                    name: 'SysMenu',
                    title: '菜单管理',
                    icon: 'el-icon-menu',
                    path: '/sys/menus',
                    children: []
                }
            ]
        },
        {
            name: 'SysTools',
            title: '系统工具',
            icon: 'el-icon-s-tools',
            path: '',
            children: [
                {
                    name: 'SysDict',
                    title: '数字字典',
                    icon: 'el-icon-s-order',
                    path: '/sys/dicts',
                    children: []
                },
            ]
        }
    ]
    let authorities = ['sys:user:list', 'sys:user:save', 'sys:user:delete', 'sys:menu:add']

    Result.data = {
        nav: nav,
        authorities: authorities
    }
    return Result
})


Mock.mock('/sys/menu/list', 'get', () => {
    Result.data = [
        {
            id: 1,
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄',
            status: 0,
            perms: 'sys:manage',
        },
        {
            id: 2,
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄',
            type: 0,
            children: [
                {
                    id: 21,
                    date: '2016-05-01',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1519 弄',
                    type: 1
                },
                {
                    id: 22,
                    date: '2016-05-03',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1516 弄',
                    type: 2
                }
            ]
        },
    ]
    return Result
})


Mock.mock(RegExp('/sys/role/info/*'), 'get', () => {
    Result.data = {
        "id": 6,
        "status": 1,
        "name": "超级管理员",
        "code": "admin",
        "remark": "系统默认最高权限，不可以编辑和任意修改",
        "menuIds": [3]
    }
    return Result;
})
